<template>
  <div class="rink">
    <div class="container">
      <div class="officialList">
        <div class="title">官方榜</div>
        <!-- 还是使用v-if解决，数据还没有传入，就开始使用了(异步数据的问题) -->
        <div v-if="rinkList.length">
          <RinkCard :rinkData="rinkList[0]" />
          <RinkCard :rinkData="rinkList[1]" />
          <RinkCard :rinkData="rinkList[2]" />
          <RinkCard :rinkData="rinkList[3]" />
        </div>
        <ul class="orderRink" v-if="rinkList.length">
          <li class="item">
            <Card :dataList="otherList" :isPlayCount="true" title="全球榜"/>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import RinkCard from '../../components/RinkCard'
import Card from '../../components/Card'
export default {
  name: 'Rink',
  components: {
    RinkCard,
    Card
  },
  data () {
    return {
      rinkList: [], // 排行榜
      otherList: [] // 剩余的排行榜
    }
  },
  methods: {
    async getRinkList () {
      const res = await this.$http.get('/toplist')
      this.rinkList = res.data.list
      // 除了最上面的四个其他的都在底下排序
      const data = res.data.list.slice(4)
      data.map(item => {
        item.picUrl = item.coverImgUrl
      })
      this.otherList = data
    }
  },
  created () {
    this.getRinkList()
  }
}
</script>

<style lang="less" scoped>
.rink {
  margin-top: 30px;
}
.container {
  width: 1100px;
  margin: 0 auto;
}
.officialList {
  width: 100%;
  .title {
    padding-top: 10px;
    font-size: 20px;
    font-weight: 600;
  }
}
</style>
